BigDFT.Interop.XTBInterop module

This module contains some wrappers for using XTB to perform calculations.

https://xtb-docs.readthedocs.io/en/latest/contents.html

class XTBCalculator(omp='1', dry_run=False, skip=False, verbose=True)[source]

Bases: BigDFT.Calculators.Runner

A calculator which can drive simulations using the XTB program.

XTB uses a mixed approach for control. First, you can pass command line arguments to the program. Second, you can modify the input file. We mirror this split here. Command line arguments can be passed as arguments to the run command. To modify the input file, the run command accepts an argument inp which is a dictionary. This dictionary is written to the input file (in the appropriate format). See the example for more details.

https://xtb-docs.readthedocs.io/en/latest/contents.html

os = <module 'os' from '/usr/local/anaconda/lib/python3.7/os.py'>
post_processing(logname, command)[source]

Post processing the calculation.

Returns

a representation of the logfile.

Return type

(BigDFT.Interop.XTBInterop.XTBLogfile)

pre_processing()[source]

Process local run dictionary to create the input directory and identify the command to be passed

Returns

dictionary containing the command to be passed to process_run()

Return type

dict

process_run(command)[source]

Run the xtb executable.

class XTBLogfile(sys, logname, opt=False, md=False)[source]

Bases: object

This class stores the results of an XTB calculation which might be later post-processed.

sys

a handle to the original system used in the calculation.

Type

BigDFT.Systems.System

log

a string representation of the logfile from XTB.

Type

str

charges

charge values computed by XTB.

Type

list

opt_energy

a list of energy values from the geometry optimization procedure.

Type

list

opt_fnorm

a list of gradient norm values from the geometry optimization procedure.

Type

list

opt_traj

a list of BigDFT.Systems.System from the geometry optimization procedure.

Type

list

md_energy

a list of energy values from the MD simulation.

Type

list

md_fnorm

a list of gradient norm values from the MD simulation.

Type

list

md_traj

a list of BigDFT.Systems.System from the MD simulation.

Type

list

property energy

The total energy of the system.

property gfnff_qest

When using the GFNFF option, no charges are computed. Instead, there are estimated charges when the topology is generated. This will extract those values.

property gradient_norm

The total gradient of the system.

property homo_lumo_gap

The homo lumo gap of the system.

xtb_equilibrate(sys, calc, prod_time=20, **kwargs)[source]

This function will automate the process of taking a system from zero temperature up to room temperature (298.15 kelvin).

This routine will work by performing 10ps simulations at temperatures from 0 to 298.15 kelvin, with each simulation spaced by 10 degrees (310 ps total). Finally, the production run can be performed.

Parameters
Returns

a list of positions along the trajectory and a list of energy values.

Return type

(list, list)

BigDFT.Interop.XTBInterop example

Below we show an example of using the XTB interoperability functions.

def _example():
    """Example of using XTB interoperability"""
    from BigDFT.IO import XYZReader
    from BigDFT.Systems import System
    from BigDFT.Fragments import Fragment
    from os.path import join
    from copy import deepcopy

    # Create a system.
    reader = XYZReader("Ar")
    fsys = System()
    fsys["FRA:1"] = Fragment(xyzfile=reader)
    fsys["FRA:2"] = deepcopy(fsys["FRA:1"])
    fsys["FRA:2"].translate([-2, 0, 0])

    # Create a calculator.
    code = XTBCalculator()
    log = code.run(sys=fsys, name="test", run_dir="work")

    # Print some values.
    print(log.energy)
    print(log.gradient_norm)
    print(log.homo_lumo_gap)
    print(log.charges)

    # Geometry optimization.
    log = code.run(sys=fsys, name="opt", opt=True, run_dir="work")
    sys2 = log.optimized_geometry
    # this also works
    sys2 = log.opt_traj[-1]
    print(log.opt_energy)
    print(log.opt_fnorm)

    # Recompute.
    log = code.run(sys=sys2, name="opt2", run_dir="work")
    print(log.energy)
    print(log.gradient_norm)
    print(log.homo_lumo_gap)

    # Molecular dynamics.
    inp = {}
    inp["md"] = {"temp": 300, "time": 2}
    logmd = code.run(sys=fsys, name="md", omd=True, inp=inp, run_dir="work")
    print(logmd.md_energy)
    print(logmd.md_fnorm)
    sys3 = logmd.md_traj[-1]